import Vue from 'vue';
import App from './App.vue';
import axios from 'axios';
import Lockr from 'lockr';
import _ from 'lodash';
import moment from 'moment';
import ElementUI from 'element-ui';
import '../theme/index.css';
import 'font-awesome/css/font-awesome.min.css'
import VueRouter from 'vue-router';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import filter from './assets/js/filter';
import store from './vuex/store';
import routes from './routes';
import './assets/css/theme/all-skins.css';
import './assets/plugins/fullscreen';
import tools from './assets/plugins/tools';

axios.defaults.baseURL = '';
axios.defaults.timeout = 1000 * 15;
axios.defaults.headers['Content-Type'] = 'application/json';
axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest';
if (Lockr.get('sessionId')) {
    axios.defaults.headers.sessionId = Lockr.get('sessionId');
    console.log(`sessionId: ${Lockr.get('sessionId')}`);
}

const router = new VueRouter({
    mode: 'hash',
    base: __dirname,
    routes
});

router.beforeEach((to, from, next) => {
    // const hideLeft = to.meta.hideLeft
    // store.dispatch('showLeftMenu', hideLeft)
    // store.dispatch('showLoading', true)
    NProgress.start();
    next();
});

router.afterEach(transition => {
    NProgress.done();
});

Vue.use(ElementUI);
Vue.use(VueRouter);

window.moment = moment;
window.axios = axios;
window._ = _;
window.Lockr = Lockr;
window.tools = tools;

const bus = new Vue();
window.bus = bus;

new Vue({
    el: '#app',
    template: '<App/>',
    filters: filter,
    router,
    store,
    components: { App }
}).$mount('#app');

